/*
 * Copyright (c) 2013 iTAC Software AG, Germany. All Rights Reserved.
 * 
 * This software is protected by copyright. Under no circumstances may any part of this file in any form be copied,
 * printed, edited or otherwise distributed, be stored in a retrieval system, or be translated into another language
 * without the written permission of iTAC Software AG.
 */
package org.template.portal;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

// TODO
/**
 * @author rafal.kojta
 */
@Entity
@Table(name = "student_group")
@AssociationOverrides({ @AssociationOverride(name = "pk.student", joinColumns = @JoinColumn(name = "STUDENT_ID")),
    @AssociationOverride(name = "pk.yearGroup", joinColumns = @JoinColumn(name = "YEAR_GROUP_ID")) })
public class StudentGroup {

  @EmbeddedId
  private StudentGroupId pk = new StudentGroupId();

  @Column(name = "IS_MODERATOR")
  private boolean isModerator;

  public StudentGroup() {

  }

  public StudentGroupId getPk() {
    return pk;
  }

  public void setPk(StudentGroupId pk) {
    this.pk = pk;
  }

  public boolean isModerator() {
    return isModerator;
  }

  public void setModerator(boolean isModerator) {
    this.isModerator = isModerator;
  }

  @Transient
  public Student getStudent() {
    return getPk().getStudent();
  }

  public void setStudent(Student student) {
    getPk().setStudent(student);
  }

  @Transient
  public YearGroup getYearGroup() {
    return getPk().getYearGroup();
  }

  public void setYearGroup(YearGroup yearGroup) {
    getPk().setYearGroup(yearGroup);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;

    StudentGroup that = (StudentGroup) o;

    if (getPk() != null ? !getPk().equals(that.getPk()) : that.getPk() != null)
      return false;

    return true;
  }

  @Override
  public int hashCode() {
    return (getPk() != null ? getPk().hashCode() : 0);
  }

}
